/**
 * Created by WT-SUN on 2017/5/16.
 */
$(function () {
    var userId= $.getQueryParam('id');
    recordsInfo(userId);
    certInfo(userId);
});
function recordsInfo(userId) {
    $('#recTb').datagrid({
        rownumbers: true,//显示行号
        striped: true,
        fit: true,
        singleSelect: true,
        sortOrder: true,
        fitColumns: true,
        height: 340,
        url: ROOT_PATH + '/train/certificate/selectRecordsByUserId.shtml?userId='+userId,
        columns: [[
            {field: 'name', title: '培训班名称',width: 200},
            {field: 'trainContent', title: '培训内容', width: 200},
            {field: 'proTypeIdName', title: '专业列别', width: 100},
            {field: 'trainLevelIdName', title: '培训级别', width: 100},
            {field: 'trainTypeIdName', title: '培训类别', width: 100},
            {field: 'actualStartTime', title: '实际开班日期', width: 100},
            {field: 'actualTrainHour', title: '实际培训学时', width: 100},
            {field: 'isQualified', title: '是否合格', width: 60,
                formatter: function (value, row, index){
                    return row.isQualified=='1'?'是':(row.isQualified=='0'?'否':'');
                }},
            {field: 'score', title: '成绩', width: 60}
        ]]
    });
}
function certInfo(userId) {
    $('#cerTb').datagrid({
        rownumbers: true,//显示行号
        striped: true,
        fit: true,
        singleSelect: true,
        sortOrder: true,
        fitColumns: true,
        height: 300,
        url: ROOT_PATH + '/train/certificate/selectCertByUserId.shtml?userId='+userId,
        columns: [[
            {field: 'name', title: '证书名称',width: 100},
            {field: 'certificateName', title: '证书种类', width: 100},
            {field: 'num', title: '证书编号', width: 100},
            {field: 'issueAuthority', title: '发证机关级别', width: 100},
            {field: 'isCerId', title: '是否有效', width: 100,formatter: function (value, row, index) {
                if(row.isCerId==null){
                    return '<span class="color-important text-white" style="padding: 3px;border-radius:5px;">否</span>';
                }else {
                    var b1=false;var b2=false;
                    if (row.isReview=='1'){
                        if (typeof (row.nextReviewTime) == 'undefined' || row.nextReviewTime == null) {
                            b1=false;
                        }else {
                            var now = new Date();
                            var dateR = new Date(row.nextReviewTime);
                            if (dateR > now){
                                b1=true;
                            }
                        }
                    }else {
                        b1=true;
                    }
                    if (row.isChanged=='1'){
                        if (typeof (row.nextChangedTime) == 'undefined' || row.nextChangedTime == null) {
                            b2=false;
                        }else {
                            var now = new Date();
                            var dateC = new Date(row.nextChangedTime);
                            if (dateC > now){
                                b2=true;
                            }
                        }
                    }else {
                        b2=true;
                    }

                    if (b1&&b2){
                        return '<span class="color-success text-white" style="padding: 3px;border-radius:5px;">是</span>';
                    } else{return '<span class="color-important text-white" style="padding: 3px;border-radius:5px;">否</span>';}
                }

                //return row.isCerId==null?'<span class="color-important text-white" style="padding: 3px;border-radius:5px;">否</span>':'<span class="color-success text-white" style="padding: 3px;border-radius:5px;">是</span>';
            }},
            {field: 'nextReviewTime', title: '下次复审日期', width: 100},
            {field: 'nextChangedTime', title: '下次换证日期', width: 100}
        ]]
    });
}